package com.ziguang.redwood.web.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Record;
import com.ziguang.redwood.web.service.NewsCenterService;
import com.ziguang.redwood.web.service.ProductCenterService;

@ControllerBind(controllerKey = "/webNews", viewPath = "/")
public class NewsCenterController extends Controller{

	/**
	 * 获取文章信列表
	 */
	public void index(){
		String pageNum = this.getPara("pageNum");
		if(pageNum == null){
			pageNum = "1";
		}
		Integer num = Integer.parseInt(pageNum);
		if(num <= 0){
			num = 1;
		}
		List<Record> list = NewsCenterService.me.findNewsList();
		List<Record> productType = ProductCenterService.me.findProductType();
		Record totalPage = NewsCenterService.me.findCount();
		setAttr("totalPage", totalPage);
		setAttr("productType", productType);
		setAttr("newsList",list);
		setAttr("pageNum", num);
		render("news_center.html");
		
	}
	
	/**
	 * 获取文章详细信息
	 */
	public void newsDetail(){
		String id = this.getPara("id");
		Record list = NewsCenterService.me.findNewsDetail(id);
		List<Record> productType = ProductCenterService.me.findProductType();
		setAttr("productType", productType);
		setAttr("news",list);
		render("news_detail.html");
		
	}
	
}
